<script setup lang="ts">
import { ref } from 'vue'
import { useUserStore } from '@/stores/user'
import { RouterView } from 'vue-router'
import { useRouter } from 'vue-router'

const userStore = useUserStore()
const showUserMenu = ref(false)
const router = useRouter()

const toggleUserMenu = () => {
  showUserMenu.value = !showUserMenu.value
}

const handleLogout = () => {
  userStore.logout()
  router.push('/login')
}
</script>

<template>
  <div class="layout-container">
    <!-- 顶部导航栏 -->
    <header class="header">
      <div class="logo">
        <img src="@/assets/logo.svg" alt="Logo" class="logo-img" />
        <span class="logo-text">协同办公系统</span>
      </div>
      
      <div class="user-info">
        <div class="notifications">
          <span class="notification-badge">3</span>
          <i class="fas fa-bell"></i>
        </div>
        
        <div class="user-menu" @click="toggleUserMenu">
          <img :src="userStore.avatar" alt="用户头像" class="avatar" />
          <span class="username">{{ userStore.username }}</span>
          
          <div v-show="showUserMenu" class="dropdown-menu">
            <a href="#" class="menu-item">
              <i class="fas fa-user"></i>
              个人中心
            </a>
            <a href="#" class="menu-item">
              <i class="fas fa-cog"></i>
              设置
            </a>
            <a href="#" class="menu-item logout" @click.prevent="handleLogout">
              <i class="fas fa-sign-out-alt"></i>
              退出登录
            </a>
          </div>
        </div>
      </div>
    </header>

    <div class="main-container">
      <!-- 侧边栏 -->
      <aside class="sidebar">
        <nav class="nav-menu">
          <a href="#" class="nav-item active">
            <i class="fas fa-file-alt"></i>
            <span>我的文档</span>
          </a>
          <a href="#" class="nav-item">
            <i class="fas fa-users"></i>
            <span>协作空间</span>
          </a>
          <a href="#" class="nav-item">
            <i class="fas fa-star"></i>
            <span>收藏文档</span>
          </a>
          <a href="#" class="nav-item">
            <i class="fas fa-trash"></i>
            <span>回收站</span>
          </a>
        </nav>
      </aside>

      <!-- 主要内容区域 -->
      <main class="content">
        <RouterView />
      </main>
    </div>
  </div>
</template>

<style scoped>
.layout-container {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.header {
  height: 64px;
  background-color: #ffffff;
  border-bottom: 1px solid #e5e7eb;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: fixed;
  width: 100%;
  top: 0;
  z-index: 50;
}

.logo {
  display: flex;
  align-items: center;
}

.logo-img {
  height: 32px;
  width: 32px;
}

.logo-text {
  font-size: 1.25rem;
  font-weight: bold;
  margin-left: 8px;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 16px;
}

.notifications {
  position: relative;
  cursor: pointer;
}

.notification-badge {
  position: absolute;
  top: -8px;
  right: -8px;
  background-color: #ef4444;
  color: white;
  font-size: 0.75rem;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.user-menu {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
}

.username {
  color: #374151;
}

.dropdown-menu {
  position: absolute;
  right: 0;
  top: 100%;
  margin-top: 8px;
  width: 192px;
  background-color: white;
  border-radius: 8px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  padding: 8px 0;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  color: #374151;
  text-decoration: none;
}

.menu-item:hover {
  background-color: #f3f4f6;
}

.menu-item.logout {
  color: #ef4444;
}

.main-container {
  display: flex;
  margin-top: 64px;
  height: calc(100vh - 64px);
}

.sidebar {
  width: 256px;
  background-color: #f9fafb;
  border-right: 1px solid #e5e7eb;
  padding: 16px;
  position: fixed;
  left: 0;
  height: 100%;
}

.nav-menu {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  border-radius: 8px;
  color: #374151;
  text-decoration: none;
}

.nav-item:hover {
  background-color: #f3f4f6;
}

.nav-item.active {
  background-color: #eff6ff;
  color: #3b82f6;
}

.content {
  flex: 1;
  margin-left: 256px;
  padding: 24px;
  background-color: #f9fafb;
}
</style> 